package class11;

import class10.TreeTools;
import class10.TreeTools.*;
import java.util.*;

/**
 * <a href="https://leetcode.cn/problems/binary-tree-level-order-traversal/">102. 二叉树的层序遍历</a>
 */
public class Code01_LevelTraversalBT {
    // 层序遍历
    public static void levelTraversal(TreeNode root) {
        Queue<TreeNode> queue = new ArrayDeque<>();
        if (root == null) {
            return;
        }
        queue.add(root);
        while (!queue.isEmpty()) {
            root = queue.poll();
            System.out.printf("%d ", root.value);
            if (root.left != null) {
                queue.add(root.left);
            }
            if (root.right != null) {
                queue.add(root.right);
            }
        }
    }

    public static void main(String[] args) {
        TreeNode node = TreeTools.stringToTreeNode("[1,2,3,4,5,6,7,8,9]");
        levelTraversal(node);
    }
}